package com.zhuxulin.nokia;

import java.io.DataInputStream;
import java.io.PrintStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

public class HttpRequest {
	public String getRequest(String url) {
		HttpConnection httpConn = null;
		DataInputStream dis = null;
		String sql;
		try {
			StringBuffer responseMSG = new StringBuffer("");
			httpConn = (HttpConnection) Connector.open(url);
			if (httpConn.getResponseCode() == 200) {
				dis = httpConn.openDataInputStream();
				int ch;
				while ((ch = dis.read()) != -1) {
					responseMSG.append((char) ch);
				}
			}
			sql = responseMSG.toString();
			if (sql.startsWith("\"")) {
				sql = sql.substring(1, sql.length() - 1);
			}
			sql = new String(sql.getBytes("iso8859-1"), "utf-8");
			System.out.println(sql);
		} catch (Exception ex) {
			ex.printStackTrace();
			sql = "Network connection failure:";
		}

		return sql;
	}
}